package com.example.other.thread;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TestThread {
    public static void main(String[] args) {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        int j=1;
        for (int i=1; i<=100;i++){
            trun(executorService, j = 1<<j, i);
        }
    }

    public static void trun(ScheduledExecutorService executorService, int j, int i){
        //同一时间有100个线程会进队列。分别会等1、2、4、16、65536秒然后输出，因为只有一个线程工作，所以同一时间只有一个输出
        executorService.schedule(new Thread(() ->
                System.out.println("Time now is " + DateTime.now().toString("HH:mm:ss") + "; delayTime" +j + ";第" + i + " name" + Thread.currentThread().getName())), j, TimeUnit.SECONDS);
    }
}
